package factorybean;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.Proxy;

public class FactoryBean11<T> implements FactoryBean<T> {

	private Class<T> mapperInterface;

	public FactoryBean11(Class<T> mapperInterface) {
		this.mapperInterface = mapperInterface;
	}

	@Override
	public T getObject() throws Exception {
		return (T)newInstance(new MapperProxy());
	}

	@Override
	public Class<?> getObjectType() {
		return mapperInterface;
	}


	@SuppressWarnings("unchecked")
	protected T newInstance(MapperProxy<T> mapperProxy) {
		return (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(), new Class[] { mapperInterface }, mapperProxy);
	}



}
